// run: $exec < input
#include <iostream>

int const maxn = 50;
int const opt[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
int a[maxn][maxn];

int main()
{
	std::ios_base::sync_with_stdio(false);
	int n, m;
	std::cin >> n >> m;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++) std::cin >> a[i][j];

	int k; std::cin >> k;
	for (int i = 0; i < k; i++) {
		int x, y;
		std::cin >> x >> y;
		a[x][y] += 2;
		for (int j = 0; j < 4; j++)
			a[x + opt[j][0]][y + opt[j][1]] += 1;
	}

	bool ok = true;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++) {
			a[i][j] %= 3;
			if (a[i][j]) ok = false;
		}
	if (ok) std::cout << "YES\n";
	else std::cout << "NO\n";
}

